home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
ip
/
ka9q
/
src.arc
/
ASY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-16
|
3KB
|
131 lines
#include <stdio.h>
#include "global.h"
#include "iface.h"
#include "asy.h"
#include "ax25.h"
#include "kiss.h"
#include "slip.h"
#include "nrs.h"
#include "config.h"
#include "proc.h"
#include "commands.h"
/* Attach a serial interface to the system
* argv[0]: hardware type, must be "asy"
* argv[1]: I/O address, e.g., "0x3f8"
* argv[2]: vector, e.g., "4"
* argv[3]: mode, may be:
* "slip" (point-to-point SLIP)
* "ax25" (AX.25 frame format in SLIP for raw TNC)
* "nrs" (NET/ROM format serial protocol)
* argv[4]: interface label, e.g., "sl0"
* argv[5]: receiver ring buffer size in bytes
* argv[6]: maximum transmission unit, bytes
* argv[7]: interface speed, e.g, "9600"
*/
int
asy_attach(argc,argv,p)
int argc;
char *argv[];
void *p;
{
register struct iface *if_asy;
int16 dev;
int mode;
if(Nasy >= ASY_MAX){
printf("Too many asynch controllers\n");
return -1;
}
if(if_lookup(argv[4]) != NULLIF){
printf("Interface %s already exists\n",argv[4]);
return -1;
}
if(strcmp(argv[3],"slip") == 0)
mode = SLIP_MODE;
else if(strcmp(argv[3],"ax25") == 0)
mode = AX25_MODE;
else if(strcmp(argv[3],"nrs") == 0)
mode = NRS_MODE;
else
mode = UNKNOWN;
dev = Nasy++;
/* Create interface structure and fill in details */
if_asy = (struct iface *)calloc(1,sizeof(struct iface));
if_asy->name = strdup(argv[4]);
if_asy->mtu = atoi(argv[6]);
if_asy->dev = dev;
if_asy->stop = asy_stop;
Slip[dev].iface = if_asy;
switch(mode){
#ifdef SLIP
case SLIP_MODE:
if_asy->ioctl = asy_ioctl;
if_asy->send = slip_send;
if_asy->output = NULLFP; /* ARP isn't used */
if_asy->raw = slip_raw;
if_asy->flags = 0;
Slip[dev].type = TYPE_IP;
newproc("asy rx",256,asy_rx,dev,NULL,NULL);
break;
#endif
#ifdef AX25
case AX25_MODE: /* Set up a SLIP link to use AX.25 */
axarp();
if(Mycall.call[0] == '\0'){
printf("set Mycall first\n");
free(if_asy->name);
free((char *)if_asy);
Nasy--;
return -1;
}
if_asy->ioctl = kiss_ioctl;
if_asy->send = ax_send;
if_asy->output = ax_output;
if_asy->raw = kiss_raw;
if(if_asy->hwaddr == NULLCHAR)
if_asy->hwaddr = malloc(sizeof(Mycall));
memcpy(if_asy->hwaddr,(char *)&Mycall,sizeof(Mycall));
Slip[dev].type = TYPE_KISS;
newproc("asy rx",256,asy_rx,dev,NULL,NULL);
break;
#endif
#ifdef NRS
case NRS_MODE: /* Set up a net/rom serial iface */
/* no call supplied? */
if(Mycall.call[0] == '\0'){
printf("set mycall first\n");
free(if_asy->name);
free(if_asy);
Nasy--;
return -1;
}
if_asy->ioctl = asy_ioctl;
if_asy->send = ax_send;
if_asy->output = ax_output;
if_asy->raw = nrs_raw;
if_asy->hwaddr = malloc(sizeof(Mycall));
memcpy(if_asy->hwaddr,(char *)&Mycall,sizeof(Mycall));
Nrs[dev].iface = if_asy;
newproc("nrs rx",256,nrs_recv,dev,NULL,NULL);
break;
#endif
default:
printf("Mode %s unknown for interface %s\n",
argv[3],argv[4]);
free(if_asy->name);
free((char *)if_asy);
Nasy--;
return -1;
}
if_asy->next = Ifaces;
Ifaces = if_asy;
asy_init(dev,if_asy,argv[1],argv[2],(unsigned)atoi(argv[5]));
asy_speed(dev,atoi(argv[7]));
return 0;
}